package service.dataBase;

import java.sql.PreparedStatement;
import java.sql.SQLException;

import service.exceptions.DBInsertException;

public class InsertData {

	private DataBase db;
	private PreparedStatement preparedStatment;
	
		public InsertData(DataBase db) {
			this.db = db;
		}

		public void insertIntoProductos(String[] data) throws DBInsertException{
		
			try {
				preparedStatment=db.getConnection().prepareStatement("INSERT INTO productos (nombre,precio,id_categoria,descripcion)  VALUES (?,?,?,?)");
				preparedStatment.setString(1, data[0]);
				preparedStatment.setDouble(2, Double.valueOf(data[1]));
				preparedStatment.setInt(3, Integer.valueOf(data[2]));
				preparedStatment.setString(4, data[3]);
				preparedStatment.executeUpdate();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				throw new DBInsertException(null);
			}
		
				
		}
}
